package net.lgpage.util;

import java.io.File;
import java.io.FileNotFoundException;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;

public class IntentUtil {

	public static Intent getShareIntent(String subject, String content) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		//intent.setType("image/*");
		intent.setType("text/plain");
		// intent.setPackage("com.sina.weibo");
		intent.putExtra(Intent.EXTRA_TITLE, subject);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
		intent.putExtra(Intent.EXTRA_TEXT, content);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		return intent;
	}
	public static Intent installApk(File apkfile){
		Intent i = new Intent(Intent.ACTION_VIEW);  
        i.setDataAndType(Uri.parse("file://" + apkfile.toString()), "application/vnd.android.package-archive");   
       return i;
	}
	public static Intent takePhoto(){
		Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
		return it;
	}
	public static Intent openFile(File file)throws FileNotFoundException{  
        if (!file.exists()) {  
           throw new FileNotFoundException();
        }
        Intent i = null;
        if(file.getName().contains(".doc")){
        	i = FileIntentUtil.getWordFileIntent(file.getPath());
		}else if(file.getName().contains(".ppt")){
			   i = FileIntentUtil.getPptFileIntent(file.getPath());
		}else if(file.getName().contains(".xls")){
			   i = FileIntentUtil.getExcelFileIntent(file.getPath());
		}else if(file.getName().contains(".pdf")){
			 i = FileIntentUtil.getPdfFileIntent(file.getPath());
		}else if(file.getName().contains(".txt")){
			 i = FileIntentUtil.getWordFileIntent(file.getPath());
		}else if(file.getName().contains(".jpg")||file.getName().contains(".png")){
			 i = FileIntentUtil.getImageFileIntent(file.getPath());
		}else{
			 i = FileIntentUtil.getWordFileIntent(file.getPath());
		}
        return i;
    }  
	
	public static Intent sendMsg(String number,String message){
		Uri uri = Uri.parse("smsto:" + number);
	    Intent sendIntent = new Intent(Intent.ACTION_VIEW, uri);
	    sendIntent.putExtra("sms_body", message);
	    return sendIntent;
	}
	
	public static Intent toCall(String number){
		 Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+number));  
		 return intent;
	}
}
